package com.base.cn.platform.os.controller.web.op.giftCard;

import com.base.cn.platform.os.common.WebBaseController;
import com.base.cn.platform.os.service.manage.op.giftcard.OpGiftCardCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ll
 * @date 2018/5/30 17:44
 */
@Controller
@RequestMapping("/web/uc/op")
public class WebOpGiftCardController extends WebBaseController {

    @Autowired
    private OpGiftCardCodeService opGiftCardCodeService;


    /**
     * 我的礼品卡列表
     * @param request
     * @return
     */
    @RequestMapping("/ajax/myAjaxGiftCard")
    public String myAjaxGiftCard(HttpServletRequest request, Model model){
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        Map<String,Object> params = new HashMap<>();
        params.put("userId",userId);
        params.put("status",1);
        List<Map<String,Object>> giftCardCodes =opGiftCardCodeService.queryOpGiftCardCodeList(params,true,true,false);
        model.addAttribute("giftCardList",giftCardCodes);
        return resultPage("/op/myAccount/u-ajax-myGiftCard");
    }

    /**
     * 我的礼品卡
     * @param request
     * @return
     */
    @RequestMapping("/myGiftCard")
    public String myGiftCard(HttpServletRequest request){
        return resultPage("/op/myAccount/u-myGiftCard");
    }

    /**
     * 激活礼卡
     * @param request HttpServletRequest
     * @param id 礼卡ID
     * @param code 礼卡编码
     * @param codePwd 礼卡密码
     * @return Map<String,Object>
     */
    @RequestMapping("/activateGiftCardCode")
    @ResponseBody
    public Map<String,Object> activateGiftCardCode(HttpServletRequest request,
                                                   @RequestParam(value = "id",defaultValue = "0",required = false) BigDecimal id,
                                                   @RequestParam(value = "code",required = false) String code,
                                                   @RequestParam(value = "codePwd",required = false) String codePwd){
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        return opGiftCardCodeService.activateGiftCard(id,userId,code,codePwd);
    }


}
